package net.zjitc.service.impl;


import net.zjitc.common.Msg;
import net.zjitc.common.ServiceResponse;
import net.zjitc.mapper.UserMapper;
import net.zjitc.pojo.User;
import net.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author admin
 * @Date 2019/4/24 14:13
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;


    @Override
    public void register(User user) {
        userMapper.register(user);
    }

    @Override
    public User findByName(String username) {
        return userMapper.findByName(username);
    }

    @Override
    public Msg checkEmail(User user) {
        return getMsg(user);
    }

    private Msg getMsg(User user) {
        int resoutCount = userMapper.checkEmail(user.getEmail());
        Msg msg = new Msg();
        if (resoutCount == 0){
            msg.setFlag(true);
        }else {
            msg.setFlag(false);
        }
        return msg;
    }

    @Override
    public Msg checkUsername(User user) {
        return getMsg(user);
    }
}
